package com.zwps.common.api.validator;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;

import com.zwps.common.tool.enums.InterfaceEnum;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 参数选项校验
 * 
 * @ClassName: Option
 * @Description: 校验值必须在选项列表中
 * @author lyh
 * @date 2023年5月23日 上午11:55:08
 *
 */
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RUNTIME)
@Repeatable(EnumOption.List.class)
@Documented
@Constraint(validatedBy = { EnumOptionValidator.class })
public @interface EnumOption {

    String message() default "不在选项值列表中";

    /**
     * 选项值
     */
    Class<? extends InterfaceEnum<?>> value();

    /**
     * @return the groups the constraint belongs to
     */
    Class<?>[] groups() default {};
    
    Class<? extends Payload>[] payload() default {};
    
    @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
    @Retention(RUNTIME)
    @Documented
    @interface List {
        EnumOption[] value();
    }
}